﻿using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace DotNetUI.Models
{
    /// <summary>
    /// 枚举数据源
    /// </summary>
    public class EnumberableSource : ObservableCollection<object>
    {
        private int start;
        private int count;

        /// <summary>
        /// 开始值
        /// </summary>
        public int Start
        {
            get => start; set
            {
                start = value;
                ValueChanged();
            }
        }
        /// <summary>
        /// 结束值
        /// </summary>
        public new int Count
        {
            get => count; set
            {
                count = value;
                ValueChanged();
            }
        }

        /// <summary>
        /// 字符串格式
        /// </summary>
        public string StringFormat { get; set; } = "{0}";
        protected void ValueChanged()
        {
            var numbers = Enumerable.Range(Start, Count);
            var display = numbers.Select(p => String.Format(StringFormat, p));
            this.Clear();
            foreach (var item in display)
            {
                this.Add(item);
            }

        }
    }
}
